package com.sky.controller.admin;

import com.sky.properties.AliOssProperties;
import com.sky.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

@RestController
@RequestMapping("/admin/common")
@Slf4j
public class CommonController {
    @Autowired
    private AliOssProperties aliOssProperties;
    @RequestMapping("/upload")
    public Result<String> upload(MultipartFile file) throws RuntimeException, IOException {
        log.info("文件上传：{}",file);
        String filenameUUID = UUID.randomUUID().toString() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));


        String url = aliOssProperties.upload(file.getBytes(), filenameUUID);

        log.info("文件上传成功：{}",url);
        return Result.success(url);
    }
}
